{createAction} = require('redux-actions')

actions =
  getListStart:createAction('HXJG/GET_LIST_START')
  getListCompleted:createAction('HXJG/GET_LIST_COMPLETED')
  refreshListStart:createAction('HXJG/REFRESH_LIST_START')
  refreshListCompleted:createAction('HXJG/REFRESH_LIST_COMPLETED')
  fetchGetList:()->
    (dispatch)->
      debugger
      dispatch actions.getListStart()
      # fetch("http://202.136.214.173/api/T_CODE_SAILNOTICE",{
      #     method: 'GET'
      #     mode: 'cors'
      #     cache: 'default'
      #     headers: { 'Content-Type':'application/x-www-form-urlencoded'}
      #     # body:"pageNum=#{pageNum}&state=1"
      #   })
      debugger
      fetch("http://www.navguide.cn/notice/list?type=1&key=-1&value=广东海事局&notice=&start%20=0&length=40",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        #获取当前时间
        dispatch actions.getListCompleted
          list:json.data
          lastFetchTime:new Date()
      .catch (err)->
        console.log(err)
  fetchRefreshList:->
    (dispatch)->
      dispatch actions.refreshListStart()
      # fetch("http://202.136.214.173/api/T_CODE_SAILNOTICE",{
      #     method: 'GET'
      #     mode: 'cors'
      #     cache: 'default'
      #     headers: { 'Content-Type':'application/x-www-form-urlencoded'}
      #     # body:"pageNum=#{pageNum}&state=1"
      #   })
      debugger
      fetch("http://www.navguide.cn/notice/list?type=1&key=-1&value=广东海事局&notice=&start%20=0&length=40",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        debugger
        res.json()
      .then (json)->
        debugger
        dispatch actions.refreshListCompleted
          list:json.data
          lastFetchTime:new Date()
      .catch (err)->
        console.log(err)

module.exports = actions
